#include <ctype.h>
#include <stdio.h>

int FindMiddle(int[], int[], int);

int main()
{
    int i, len = 0;
    printf("Input vec length: ");
    scanf("%d", &len);
    
    int vec1[len], vec2[len];
    printf("Input vec1: ");
    i = 0;
    while (i < len) 
        scanf(" %d", &vec1[i++]);

    printf("Input vec2: ");
    i = 0;
    while (i < len)
        scanf(" %d", &vec2[i++]);
    
    int MiddleValue = FindMiddle(vec1, vec2, len);
    printf("Middle Value is %d\n", MiddleValue);

    for (i = 0; i < len; i++)
        printf("%d ", vec1[i]);
    for (i = 0; i < len; i++)
        printf("%d ", vec2[i]);

    return 0;
}

int FindMiddle(int vec1[], int vec2[], int len)
{
    if (vec1[(len + 1)/2] == vec2[(len + 1)/2])
        return vec1[(len + 1)/2];
    
    if (len == 1) 
        return (vec1[0] < vec2[0]) ? vec1[0] : vec2[0];

    if (vec1[(len - 1)/2] < vec2[(len - 1)/2]) 
        return FindMiddle(vec1 + len/2, vec2, len/2);
    else 
        return FindMiddle(vec1, vec2 + len/2, len/2);
}